#ifndef _WINSYS_H
#define _WINSYS_H

#define MAXLINES 300
#define TITLELENGTH 50;
#define SCROLLLENGTH (184*23/MAXLINES)
#define BUFSIZE 1024

// #define Config_MainTextColor 16
// #define Config_MainBGColor 17

typedef struct {
	char* WS_text[MAXLINES];
	u16 tlines, curline, markline;
	char WS_title[256];
	FILE* LogFile;
} WS_struct;

struct WS_lineorders {
	char* Text;
	WS_lineorders* Next;
};

#define WS_MoveScreenUp {\
	tempbuf = malloc(49152);\
	DMA_Copy(PA_DrawBg[1]+2048+256, tempbuf, 512*23-64, DMA_32NOW);\
	DMA_Copy(tempbuf, PA_DrawBg[1]+2048, 512*23-64, DMA_32NOW);\
	free(tempbuf);}

#define WS_MoveScreenDown {\
	tempbuf = malloc(49152);\
	DMA_Copy(PA_DrawBg[1]+2048, tempbuf, 512*23-64, DMA_32NOW);\
	DMA_Copy(tempbuf, PA_DrawBg[1]+2048+256, 512*23-64, DMA_32NOW);\
	free(tempbuf);}

#define WS_MoveScreenUp8 {\
	tempbuf = malloc(49152);\
	DMA_Copy(PA_DrawBg[1]+4096, tempbuf, 512*22, DMA_32NOW);\
	DMA_Copy(tempbuf, PA_DrawBg[1]+2048, 512*22, DMA_32NOW);\
	free(tempbuf);}

#define WS_MoveScreenDown8 {\
	tempbuf = malloc(49152);\
	DMA_Copy(PA_DrawBg[1]+2048, tempbuf, 512*22, DMA_32NOW);\
	DMA_Copy(tempbuf, PA_DrawBg[1]+4096, 512*22, DMA_32NOW);\
	free(tempbuf);}

void WS_Init();
WS_struct* WS_NewWindow(u8 ShowWindow, char* Title);
void WS_CloseWindow(WS_struct* winclose, WS_struct* winopen);
void WS_ShowWindow(WS_struct* window);
void WS_ScrollUp();
void WS_ScrollDown();
void WS_Update();
void WS_AddLine(WS_struct* Window, char* str, u8 DTextColor, u8 DBackColor);
void WS_fAddLine(WS_struct* Window, u8 DTextColor, u8 DBackColor, char* sformat, ...);
void WS_SetTitle(WS_struct* Window, char* Title);
void WS_TitleDraw();
void WS_RedrawWindow();
u8 WS_StartLog(WS_struct* Window, char* FileName);
void WS_StopLog(WS_struct* Window);
void WS_ClearWindow(WS_struct* window);

#endif //_WINSYS_H
